#ifndef LEETCODE_CN_CPP_PROBLEMS_7_H
#define LEETCODE_CN_CPP_PROBLEMS_7_H

#include <cstdint>

using namespace std;

namespace problem_7
{

class Solution
{
public:
    int reverse(int x)
    {
        long res = 0;
        bool isSigned = false;
        long xx = x;
        if (xx < 0)
        {
            isSigned = true;
            xx = -xx;
        }
        while (xx > 0)
        {
            res = res * 10 + xx % 10;
            xx /= 10;
        }
        if (isSigned)
        {
            res = -res;
        }
        if (res > INT32_MAX || res < INT32_MIN)
        {
            return 0;
        }
        return res;
    }
};

} // namespace problem_7

#endif //LEETCODE_CN_CPP_PROBLEMS_7_H
